import { initData } from '@/api/data'

export default {
    data() {
        return {
            loading: true, 
            url: '', params: {}, time: 170,
            data: [],
            
        }
    },
    methods: {
        async init() {
            if (!await this.beforeInit()) {
              return
            }
            return new Promise((resolve, reject) => {
                this.loading = true
                initData(this.url, this.params).then(res => {
                    // this.total = res.totalElements
                    // this.data = res.data
                    // setTimeout(() => {
                    //    this.loading = false
                    // }, this.time)
                    resolve(res)
                }).catch(err => {
                    this.loading = false
                    reject(err)
                })
            })
        },
        beforeInit() {
            return true
        },
        pageChange(e) {
            this.page = e - 1
            this.init()
        },
        sizeChange(e) {
            this.page = 0
            this.size = e
            this.init()
        }
    }
}
